package com.syh.jn.scm.service.impl.supplier.base;

import com.alibaba.dubbo.config.annotation.Service;
import com.syh.core.ddd.infrastructure.repository.AggregateRepository;
import com.syh.core.ddd.service.AbstractServiceImpl;
import com.syh.jn.scm.domain.supplier.entity.base.SupplierInvoiceInfo;
import com.syh.jn.scm.domain.supplier.repository.base.SupplierSupplierInvoiceInfoRepository;
import com.syh.jn.scm.dto.supplier.base.invoiceInfo.InvoiceInfoMto;
import com.syh.jn.scm.dto.supplier.base.invoiceInfo.InvoiceInfoSto;
import com.syh.jn.scm.dto.supplier.base.invoiceInfo.InvoiceInfoVo;
import com.syh.jn.scm.service.api.supplier.base.BusinessEntityInvoiceInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

/**
 * 开票人信息管理接口实现
 */
@Service
@Transactional
public class BusinessEntityInvoiceInfoServiceImpl extends AbstractServiceImpl<InvoiceInfoSto, InvoiceInfoMto, InvoiceInfoVo, SupplierInvoiceInfo, Long> implements BusinessEntityInvoiceInfoService {

  @Autowired
  private SupplierSupplierInvoiceInfoRepository businessEntitySupplierInvoiceInfoRepositoryImpl;

  @Override
  protected AggregateRepository<SupplierInvoiceInfo, Long> getAggregateRepository() {
    return businessEntitySupplierInvoiceInfoRepositoryImpl;
  }

  /**
   * 保存对象
   * @param sto
   * @return
   */
  @Override
  public Long save(InvoiceInfoSto sto) {
    SupplierInvoiceInfo basicInfo = SupplierInvoiceInfo.createTicketBasicInfo(sto);
    return businessEntitySupplierInvoiceInfoRepositoryImpl.add(basicInfo);
  }

  /**
   * 修改对象
   * @param mto
   */
  @Override
  public void update(InvoiceInfoMto mto) {
    SupplierInvoiceInfo basicInfo = businessEntitySupplierInvoiceInfoRepositoryImpl.getById(mto.getId());
    basicInfo.modify(mto);
      businessEntitySupplierInvoiceInfoRepositoryImpl.update(basicInfo);
  }

  /**
   * 删除对象
   * @param id
   */
  @Override
  public void delete(Long id) {
    SupplierInvoiceInfo basicInfo = businessEntitySupplierInvoiceInfoRepositoryImpl.getById(id);
    basicInfo.destroy();
      businessEntitySupplierInvoiceInfoRepositoryImpl.remove(basicInfo);
  }

}
